<?php

require_once 'ActionFramework/start.php';
require_once 'views/all.cls.php';

class RemoveUserAction extends Action {
	
	const INPUT_USER_ID = User::user_id;
	
	public function __construct() {
		parent::__construct();
		// TODO: don't allow this
		$this->add_input(RemoveUserAction::INPUT_USER_ID);
	}
	
	public function trigger($request) {
		
		global $DB;
		$user_id = $request[RemoveUserAction::INPUT_USER_ID];
		$user = $DB->get_user_by_id($user_id);
		if ($user !== null) {
			$DB->remove_user($user);
			$message = "The account has been deleted";
		}
		else {
			$message = "The account doesn't exist";
		}		
		
		// Redirects to admin action, after the user is removed.
		$action = new AdminAction();
		$view = $action->trigger($request);
		$view->add_message($message);
		
		return $view;
	}
}

?>